<?php

namespace App\Models;

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;

class MiniProgramModuleSetting extends Model
{
    //

    // public function getPicAttribute($pictures)
    // {
    //     return json_decode($pictures, true);
    // }
    // public function setPicAttribute($pictures)
    // {
    //     if (is_array($pictures)) {
    //         $this->attributes['pic'] = json_encode($pictures);
    //     }
    // }
    public function getPicAttribute()
    {
        // 如果 image 字段本身就已经是完整的 url 就直接返回
        if (Str::startsWith($this->attributes['pic'], ['http://', 'https://'])) {
            return $this->attributes['pic'];
        }
        return \Storage::disk('admin')->url($this->attributes['pic']);
    }
}
